<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>

<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/jquery.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/common.jsp"%>

<form id="uploadAvatar" name="uploadAvatar" method="post" enctype="multipart/form-data"
	action="<c:url value='/admin/user/upload/uploadAvatar' />">
	<input type="file" name="file" id="openFile" onchange="imgFileInputOnChange()">
</form>

<script type="text/javascript">
	$(function(){
		var message = '${message}';
		var result= '${result}';
		if(result=="success"){
			if(message==""){
            	return;
			}else {
				window.parent.setAvatar(message);
			}
		}
	})
	
	function imgFileInputOnChange(){
		if(!(/(?:jpg|jepg|bmp|png|gif)$/i.test($("#openFile").val()))){
			alert("暂只支持.jpg|.jepg|.bmp|.png|.gif格式的图片");
			return;
		}
		
		var _URL = window.URL || window.webkitURL;
		var file;
		if ((file = $("#openFile"))){
			var img = new Image();
			img.onload = function () {
				if(img.height!=img.width){
					alert("暂只支持上传正方形图片");
					return;
				}
				$("#uploadAvatar").submit();
			};
			img.src = _URL.createObjectURL(file.get(0).files[0]);
		}
	}
</script>